// data/excel_reader.rs
use calamine::{open_workbook_auto, Reader, RangeDeserializerBuilder};
use serde::Deserialize;
use std::error::Error;

#[derive(Deserialize, Debug, Clone)]
pub struct TestData {
    pub param1: String, // 测试数据的参数1
    pub param2: String, // 测试数据的参数2
}

impl TestData {
    // 从 Excel 文件读取测试数据
    pub fn from_excel(file_path: &str) -> Result<Vec<TestData>, Box<dyn Error>> {
        let mut workbook = open_workbook_auto(file_path)?;
        let range = workbook.worksheet_range("Sheet1")
            .ok_or("Cannot find 'Sheet1' in the Excel file")??;

        let mut iter = RangeDeserializerBuilder::new().from_range(&range)?;
        let mut data = Vec::new();

        for result in iter {
            let record: TestData = result?;
            data.push(record);
        }
        Ok(data)
    }
}
